import { Router } from "express";
import { PostController } from "../controllers";
import { deserializeUser, requireLogin, validate } from "../middlewares";
import { postSchema, updatePostSchema } from "../schemas";

const router = Router();

router.post(
  "/",
  validate(postSchema),
  deserializeUser,
  requireLogin,
  PostController.create,
);
router.get("/", PostController.findMany);
router.get("/:id", PostController.findOne);
router.patch(
  "/:id",
  validate(updatePostSchema),
  deserializeUser,
  requireLogin,
  PostController.update,
);
router.delete("/:id", deserializeUser, requireLogin, PostController.remove);
router.get("/:id/comments", PostController.findComments);

export { router as postRouter };
